/**
 * Created by Administrator on 2018/1/17.
 */

/**
 * 公共函数
 */
function plusReady() {
    // 隐藏滚动条
    plus.webview.currentWebview().setStyle({scrollIndicator: 'none'});
    // Android处理返回键
    plus.key.addEventListener('backbutton', function () {
        myApp_.closeModal();
        var currentView = myApp_.getCurrentView();
        var page_name = currentView.activePage.name;
        if (page_name == 'index' || page_name == 'login') {
            if (confirm("确认退出!")) {
                //navigator.app.exitApp();//首页点返回键退出应用
                plus.runtime.quit()
            }
            return;
        }
        if (currentView.history.length > 1) {
            currentView.router.back({});//非首页返回上一级
        } else {
            if (confirm("确认退出!")) {
                plus.runtime.quit()
            }
        }
    }, false);
    plus.runtime.getProperty(plus.runtime.appid, function (inf) {
        wgtVer = inf.version;
        console.log("版本号：" + wgtVer);
    });
    //第三方登录
    plus.oauth.getServices(function (services) {
        auths = services;
    }, function (e) {
        outSet("获取登录服务列表失败：" + e.message + " - " + e.code);
    });

    //获取设备码
    getPushInfo();
    /**
     * 推送事件处理
     */
    use('event/push');
    plus.push.setAutoNotification(false);//不显示透传信息
    // 监听在线消息事件
    plus.push.addEventListener("receive", function (msg) {
        if (msg.aps) { // Apple APNS message
            //接收到在线APNS消息
            PUSH_EVENT.aps(msg);
        } else {
            PUSH_EVENT.default(msg);
        }
    });


    PLUS_READY = 1;//混编模式
}
if (window.plus) {
    plusReady();
} else {
    document.addEventListener('plusready', plusReady, false);
}

//获取机器码   获取本地推送标识信息
function getPushInfo() {
    if(window.plus){
        var info = plus.push.getClientInfo();
        var id = info.id;
        var cid = info.clientid;//设备码
        
        window.LINXIANSHENG_CLIENT_ID = cid;
		var storage_cid = Storage_.get("client_id");
		
		if(!storage_cid || storage_cid != cid){
			request_(
	        	url_('index/User/up_client_id')
	        	,{
	        		cid: cid
	        	}
	        	,function(d){
	        		if(d.code == 0){
	        			Storage_.set("client_id", d.data);
	        		}
	        	}
	        );
		}
        
//      var img = new Image();
//      img.src = sprintf("%s/%s%s",url_('index/User/up_client_id'),"?cid=",cid);
    }
}

